package com.czy.common.model;


import com.czy.common.constant.SystemConstant;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * 返回结果封装
 * @author czy
 * @date 2021-3-29
 */
@Slf4j
@Getter
@Setter
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 7597440317140187924L;
    @ApiModelProperty(value = "响应码 200:请求成功  500:请求有误")
    private Integer code;
    @ApiModelProperty(value = "提示信息")
    private String msg;
    @ApiModelProperty(value = "响应数据")
    private T data;
    public Result() {
    }
    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }

    public static Result success(Object data,String msg){
        return new Result(SystemConstant.RESPONSE_SUCCESS_CODE,msg,data);
    }

    public static Result success(Object data){
        return new Result(SystemConstant.RESPONSE_SUCCESS_CODE,"请求成功",data);
    }

    public static Result success(){
        return new Result(SystemConstant.RESPONSE_SUCCESS_CODE,"请求成功",null);
    }

    public static Result error(String msg){
        return new Result(SystemConstant.RESPONSE_FAIL_CODE,msg);
    }

    public static Result error(String msg,Object data){
        return new Result(SystemConstant.RESPONSE_FAIL_CODE,msg,data);
    }

    public static Result error(Integer code,String msg){
        return new Result(code,msg);
    }


}
